#include "fft.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h> 

//print mod of vector
void print_vector_mod(const char *title,complex *x,int n)
{
	int i;
	printf("mod:%s (dim=%d):", title, n);
	for(i=0; i<n; i++) 
	{
		printf("%5.2f,", x[i].Re*x[i].Re + x[i].Im*x[i].Im);
	}
  	putchar('\n');
  	return;
}

//print real part of vector
void print_vector_real(const char *title,complex *x,int n)
{
	int i;
	printf("real:%s (dim=%d):", title, n);
	for(i=0; i<n; i++) 
	{
		printf("%5.2f,", x[i].Re);
	}
  	putchar('\n');
  	return;
}



int main(void)
{
	/*v[] is data vector,scratch[] is a buffo,
	fft and ifft need input vector and will put
	result into v[],but scratch[] is used by ifft and fft to put 
	temporary data*/
  	complex v[N],scratch[N];
  	int k;

  	/* Fill v[] with a serial of data */
  	for(k=0; k<N; k++) 
	{
		/*real part is data you get*/
    	v[k].Re = cos((100)*2*PI*k/(double)N);
    	/*we study real signal,so image part is zero*/
    	v[k].Im = 0;
  	}
    
  	/* FFT, iFFT of v[]: */
  	print_vector_real("Orig", v, N);
  	fft( v, N, scratch );
  	print_vector_mod(" FFT", v, N);
  	ifft( v, N, scratch );
  	print_vector_real("iFFT", v, N);
  	
  	/*you can compile and use command "fft.exe > data.txt",
	  and open you MATLAB,copy serial data want in data.txt into matrix of MATLAB
	  and use plot to see the Orig,FFT and iFFT*/

  	exit(EXIT_SUCCESS);
}
